package com.dog.modules.message.web;

import com.dog.framework.core.model.PageResult;
import com.dog.framework.core.model.ResponseResult;
import com.dog.framework.core.utils.JsonUtils;
import com.dog.modules.message.convert.SmsLogConvert;
import com.dog.modules.message.domain.entity.SmsLog;
import com.dog.modules.message.domain.query.SmsLogQuery;
import com.dog.modules.message.domain.vo.SmsLogVO;
import com.dog.modules.message.service.SmsLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 短信日志
 *
 * @author 阿沐 babamu@126.com
 * <a href="https://maku.net">MAKU</a>
 */
@Slf4j
@RestController
@RequestMapping("/message/sms/log")
@Tag(name = "短信日志")
@AllArgsConstructor
public class SmsLogController {
    private final SmsLogService smsLogService;

    @PostMapping("/page")
    @Operation(summary = "分页")
    public PageResult<SmsLogVO> page(@RequestBody @Valid SmsLogQuery query) {
        log.info("添加用户请求参数 {}", JsonUtils.toJsonString(query));
        PageResult<SmsLogVO> pageResult = smsLogService.page(query);
        log.info("返回参数 ：{}", JsonUtils.toJsonString(pageResult));
        return pageResult;
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    public ResponseResult<SmsLogVO> get(@PathVariable("id") Long id) {
        SmsLog entity = smsLogService.getById(id);
        return ResponseResult.success(SmsLogConvert.INSTANCE.convert(entity));
    }

}